package com.example.recyclerviewdemo.demo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.recyclerviewdemo.R;

import java.util.ArrayList;
import java.util.List;

public class Demo extends AppCompatActivity {
    private List<Msg> mMsgList = new ArrayList<>();

    private RecyclerView mRvChatDemo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo);
        mRvChatDemo = findViewById(R.id.rv_chat_demo);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(Demo.this);
        mRvChatDemo.setLayoutManager(linearLayoutManager);
        initMsgList();
        ChatDemoAdapter chatDemoAdapter = new ChatDemoAdapter(mMsgList);
        mRvChatDemo.setAdapter(chatDemoAdapter);

    }

    private void initMsgList() {
        for (int i = 0; i < 30; i++) {
            int type;
            if (i % 2 == 0) {
                type = Msg.TYPE_RECEIVED;
            } else {
                type = Msg.TYPE_SEND;
            }
            Msg msg = new Msg("你好" + i, type);
            mMsgList.add(msg);
        }
    }
}
